package com.gopay.bis.service.bank.query.impl;

import java.io.IOException;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.springframework.stereotype.Service;

import com.gopay.bis.service.bank.query.BisBankQueryService;
import com.gopay.common.cps.manager.bank.BankOrderQueryManager;
import com.gopay.common.domain.bank.BankOrder;
import com.gopay.common.util.JsonUtils;

@Service("bisBankQueryService")
public class BisBankQueryServiceImpl implements BisBankQueryService {
    @Resource(name = "bankOrderQueryManager")
    private BankOrderQueryManager bankOrderQuery;

    @Override
    public String getBankOrderForEnable(String gopayOrderId) {
        if (StringUtils.isBlank(gopayOrderId)) {
            return "";
        }

        BankOrder bankOrder = bankOrderQuery.getEnable(gopayOrderId);
        if (bankOrder == null) {
            return "";
        }

        try {
            return JsonUtils.toJson(bankOrder);
        } catch (JsonGenerationException e) {
            e.printStackTrace();
        } catch (JsonMappingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return "";
    }

}
